<?php

use Faker\Factory as Faker;
use App\Models\Statistics;
use App\Repositories\StatisticsRepository;

trait MakeStatisticsTrait
{
    /**
     * Create fake instance of Statistics and save it in database
     *
     * @param array $statisticsFields
     * @return Statistics
     */
    public function makeStatistics($statisticsFields = [])
    {
        /** @var StatisticsRepository $statisticsRepo */
        $statisticsRepo = App::make(StatisticsRepository::class);
        $theme = $this->fakeStatisticsData($statisticsFields);
        return $statisticsRepo->create($theme);
    }

    /**
     * Get fake instance of Statistics
     *
     * @param array $statisticsFields
     * @return Statistics
     */
    public function fakeStatistics($statisticsFields = [])
    {
        return new Statistics($this->fakeStatisticsData($statisticsFields));
    }

    /**
     * Get fake data of Statistics
     *
     * @param array $postFields
     * @return array
     */
    public function fakeStatisticsData($statisticsFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'type' => $fake->randomDigitNotNull,
            'add_users_count' => $fake->randomDigitNotNull,
            'users_count' => $fake->randomDigitNotNull,
            'goods_count' => $fake->randomDigitNotNull,
            'orders_count' => $fake->randomDigitNotNull,
            'orders_add_count' => $fake->randomDigitNotNull,
            'orders_add_pay_count' => $fake->randomDigitNotNull,
            'orders_return_count' => $fake->randomDigitNotNull,
            'orders_return_amount' => $fake->word,
            'orders_return_rate' => $fake->word,
            'repurchase_count' => $fake->randomDigitNotNull,
            'repurchase_rate' => $fake->word,
            'orders_price_amount' => $fake->word,
            'orders_pay_money_amount' => $fake->word,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $statisticsFields);
    }
}
